<template>
	<el-form :model="formData" ref="formRef" :rules="formRules" label-width="12rem">
		<el-row type="flex" :gutter="10">
			<el-col :span="24">
				<el-form-item label="轮播图" prop="img">
					<el-upload-image v-model="formData.img" :limit="1" :title="title"></el-upload-image>
				</el-form-item>
			</el-col>
			<!-- <el-col :span="12">
				<el-form-item label="链接地址" prop="url">
					<el-input v-model="formData.url" clearable placeholder="请输入链接地址"></el-input>
				</el-form-item>
			</el-col> -->
			<!-- type  1首页轮播图2商城轮播图3课程轮播图4活动轮播图5老师轮播图 6.新闻轮播图 -->
			<!-- <el-col :span="24">
				
				<el-form-item label="轮播图类型" prop="type">
					<el-radio-group v-model="formData.type">
						<el-radio :label="1">
							首页轮播图({{ 358*2 }}*{{ 130*2 }})
						</el-radio>
						<el-radio :label="2">商城轮播图({{ 360*2 }}*{{ 130*2}})</el-radio>
						<el-radio :label="3">课程轮播图({{ 390*2 }}*{{ 240*2}})</el-radio>
						<el-radio :label="4">活动轮播图({{ 390*2 }}*{{ 240*2}})</el-radio>
						<el-radio :label="5">老师轮播图({{ 390*2 }}*{{ 155*2}})</el-radio>
						<el-radio :label="6">新闻轮播图({{ 390*2 }}*{{ 155*2}})</el-radio>
					</el-radio-group>
				</el-form-item>
			</el-col> -->
			<!-- 0不跳转1活动详情2课程详情3新闻中心详情  -->
			<!-- <el-col :span="24" v-if="formData.type==1||formData.type==3||formData.type==6||formData.type==4">
				<el-form-item label="链接类型" prop="url_type">
					<el-radio-group v-model="formData.url_type" @input="changelist">
						<el-radio :label="0">不跳转</el-radio>
						<el-radio :label="2">课程</el-radio>
						<el-radio :label="1">活动</el-radio>
						<el-radio :label="3">新闻中心</el-radio>
					</el-radio-group>
				</el-form-item>
			</el-col> -->
			<!-- type 1首页轮播2商城轮播  -->
			<!-- <el-col :span="24" v-if="formData.type==1||formData.type==3||formData.type==6||formData.type==4">
				
				<el-form-item label="跳转地址" prop="order_id" v-if="formData.url_type==1">
					<el-select v-model="formData.order_id" size="mini" placeholder="请选择">
						<el-option v-for="item in jumplist" :key="item.id" :label="item.activity_name" :value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="跳转地址" prop="order_id" v-if="formData.url_type==2">
					<el-select v-model="formData.order_id" size="mini" placeholder="请选择">
						<el-option v-for="item in jumplist" :key="item.id" :label="item.course_name" :value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="跳转地址" prop="order_id" v-if="formData.url_type==3">
					<el-select v-model="formData.order_id" size="mini" placeholder="请选择">
						<el-option v-for="item in jumplist" :key="item.id" :label="item.title" :value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
			</el-col> -->
		</el-row>
		<el-row type="flex" justify="center">
			<el-button type="primary" icon="el-icon-check" @click="onConfirm">确认</el-button>
			<el-button type="default" icon="el-icon-close" @click="onCancel">取消</el-button>
		</el-row>
	</el-form>
</template>

<script>
	import { imghttp,get,post,del } from '@/assets/js/http'
	export default {
		name: "member-search",
		props: {
			formData: {
				type: Object,
				default: () => {}
			},
		},
		components: {
			"el-upload-image": () => import("@/components/el-upload-image.vue"),
		},
		data() {
			return {
				formRules: {
					img: [{
						required: true,
						message: '请选择',
						trigger: 'change'
					}],
					// type: [{
					// 	required: true,
					// 	message: '请选择',
					// 	trigger: 'change'
					// }],
					// order_id: [{
					// 	required: true,
					// 	message: '请选择',
					// 	trigger: 'change'
					// }],
				},
				title: '',
				jumplist: [],
			};
		},
		watch: {
			'formData.url_type'(value,oldValue){
				this.getlist(this.formData.url_type)
			}
		},
		methods: {
			onConfirm() {
				console.log(this.formData.url_type,'this.formData.url_type',this.formData.type)
				// if(this.formData.type==1||this.formData.type==3||this.formData.type==4||this.formData.type==6){
				// 	if(this.formData.url_type==''&&this.formData.url_type!==0){
				// 		this.$message('请选择链接类型')
				// 		return
				// 	}
				// 	if(!this.formData.order_id&&this.formData.url_type!==0){
				// 		this.$message('请选择跳转地址')
				// 		return
				// 	}
				// }
				this.$refs.formRef.validate((valid) => {
					if (valid) {
						// alert('submit!');url_type 0不跳转1活动详情2课程详情3新闻中心详情formData.order_id
						// if(this.formData.url_type==1){
						// 	this.formData.url = '/pages/actinfo/actinfo?id='+this.formData.order_id
						// }if(this.formData.url_type==2){
						// 	this.formData.url = '/pages/coursesinfo/coursesinfo?id='+this.formData.order_id
						// }if(this.formData.url_type==3){
						// 	this.formData.url = "/pagemy/newsdetail/newsdetail?id="+this.formData.order_id
						// }
						// console.log(this.formData,this.formData.url)
						this.formData.type = 4
						this.$emit("search", this.formData);
						this.$parent.$emit("update:visible", false);
						this.$refs.formRef.resetFields()
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			onCancel() {
				this.$parent.$emit("update:visible", false);
				this.$refs.formRef.resetFields();
			},
			changelist(e) {
				this.formData.order_id = ''
				if(e!==0){
					this.getlist(e) //0不跳转1活动详情2课程详情3新闻中心详情
				}
				
			},
			async getlist(n) {
				if (n == 1) {
					await get({
						url: '/admin/project.Activity/index',
						params: {
							limit: 9999
						},
					}).then(res => {
						this.jumplist = res.list
					})
				}
				if(n==2){
					await get({
						url: '/admin/project.TeacherCourse/index',
						params: {
							limit: 9999,
							status:2,
						},
					}).then(res => {
						this.jumplist = res.list
					})
				}
				if(n==3){
					await get({
						url: '/admin/wiki.news/index',
						params: {
							limit: 9999
						},
					}).then(res => {
						this.jumplist = res.list
					})
				}
				
			}
		}
	};
</script>
